all files / stepper/ stepper.vue

18.75% Statements 6/32
15.38% Branches 4/26
20% Functions 1/5
9.09% Lines 2/22
1 branch Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52    1×                                                                                                  
//
 
import stepConnector from './stepConnector'
export default {
  name: 'mu-stepper',
  props: {
    activeStep: {
      type: Number,
      default: 0
    },
    linear: {
      type: Boolean,
      default: true
    },
    orientation: {
      type: String,
      default: 'horizontal',
      validator (val) {
        return ['horizontal', 'vertical'].indexOf(val) !== -1
      }
    }
  },
  render (h) {
    const {activeStep, linear, orientation} = this
    const children = []
    if (this.$slots.default && this.$slots.default.length > 0) {
      let index = 0
      this.$slots.default.forEach((vNode) => {
        if (!vNode.componentOptions) return
        if (index > 0) {
          children.push(h(stepConnector, {}))
        }
        const propsData = vNode.componentOptions.propsData
        if (activeStep === index) {
          propsData.active = true
        } else if (linear && activeStep > index) {
          propsData.completed = true
        } else if (linear && activeStep < index) {
          propsData.disabled = true
        }
        propsData.index = index++
        children.push(vNode)
      })
      if (children.length > 0) children[children.length - 1].componentOptions.propsData.last = true
    }
    return h('div', {
      class: ['mu-stepper', orientation === 'vertical' ? 'mu-stepper-vertical' : '']
    }, children)
  }
}